package net.zoneland.knowledge.dao;

import net.zoneland.knowledge.controller.bean.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * 红色基地.
 */
@Mapper
public interface RedBaseMapper {

    /**
     * 查询基地列表.
     * @param condition 查询条件
     * @return
     */
    @Select({
        "<script>",
        "SELECT AEB.ID, AEB.CMPNAME, AEB.EDUCATION_BASE_NAME",
        " FROM AITK_RED_EDUCATION_BASE AEB ",
        " WHERE 1 = 1 ",
        "<if test=\"cmpName != null and cmpName != ''\"> AND AEB.CMPNAME=#{cmpName,jdbcType=VARCHAR} </if> ",
         " ORDER BY CMPNAME DESC ",
        "</script>"
    })
    @Results(id = "redBaseResultMap", value = {
        @Result(column = "ID", property = "id", jdbcType =  JdbcType.VARCHAR, id = true),
        @Result(column = "CMPNAME", property = "cmpName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "EDUCATION_BASE_NAME", property = "educationBaseName", jdbcType = JdbcType.VARCHAR)
    })
    List<RedBaseInfo> search(final RedBaseRouteQueryVo condition);


    /**
     * 查询路线.
     * @param  id id
     * @return 路线
     */
    @Select({
        "<script>",
        "SELECT AEB.ID, AEB.CMPNAME, AEB.EDUCATION_BASE_NAME, AEB.LOCATION, AEB.RED_TYPE, AEB.EDUCATION_BASE_DES,",
        " AEB.CONTACT, AEB.CONTACT_PHONE,AEB.RED_LEVEL, AEB.PICTURE_FILE, AEB.PICTURE_NAME, AEB.EXTENDED_FIELDS_ONE",
        " FROM AITK_RED_EDUCATION_BASE AEB ",
        " WHERE 1 = 1 ",
        "<if test=\"id != null and id != ''\"> AND AEB.ID=#{id,jdbcType=VARCHAR} </if> " ,
        "</script>"
    })
    @Results(value = {
        @Result(column = "ID", property = "id", jdbcType =  JdbcType.VARCHAR, id = true),
        @Result(column = "CMPNAME", property = "cmpName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "EDUCATION_BASE_NAME", property = "educationBaseName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "LOCATION", property = "location", jdbcType = JdbcType.VARCHAR),
        @Result(column = "RED_TYPE", property = "redType", jdbcType = JdbcType.VARCHAR),
        @Result(column = "EDUCATION_BASE_DES", property = "educationBaseDes", jdbcType = JdbcType.VARCHAR),
        @Result(column = "CONTACT", property = "contact", jdbcType = JdbcType.VARCHAR),
        @Result(column = "CONTACT_PHONE", property = "contactPhone", jdbcType = JdbcType.VARCHAR),
        @Result(column = "RED_LEVEL", property = "redLevel", jdbcType = JdbcType.VARCHAR),
        @Result(column = "PICTURE_NAME", property = "pictureName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "PICTURE_FILE", property="pictureFile", jdbcType=JdbcType.BLOB),
        @Result(column = "EXTENDED_FIELDS_ONE", property = "extendedFieldsOne", jdbcType = JdbcType.VARCHAR)
    })
    RedBaseInfoWithBlobs searchById(final String id);

}
